'''
Author: Simon
Date: 2022-03-03 19:08:21
LastEditTime: 2022-03-04 11:30:00
LastEditors: Please set LastEditors
Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
FilePath: /UICtimeTableToICS/teacher.py
'''
from cmath import inf
import requests
import ssl
import json

def teacher_data():
    context = ssl._create_unverified_context()

    datalist = []

    # for i in range(0, 67):
    for i in range(0, 20):
        url = 'https://staff.uic.edu.cn/teacher/teacher/list?access-token=&page={}&pageSize=8&key=&lang=cn'.format(i)
        teacher_info = requests.get(url, verify=False).text
        info_json = json.loads(teacher_info)
        info_json_data = info_json["data"]["data"]
        # print(info_json_data)
        
        for info in info_json_data:
            # print(info)
            data = []
            # title
            title = info["title"]
            # print(title)
            # name
            name = info["name"]
            nameTitle = title + name
            # print(nameTitle)
            data.append(nameTitle)
            # name_en
            name_en = info["name_en"]
            name_enTitle = title + name_en
            # print(name_enTitle)
            data.append(name_enTitle)
            # email
            email = info["email"]
            # print(email)
            data.append(email)
            # nation
            if info["nation"]:
                nation = info["nation"]
                # print(nation)
                data.append(nation)
            else:
                data.append("Unknown Nation")
            # position
            if info["position"]:
                position = info["position"]
                # print(position)
                data.append(position)
            else:
                data.append("Unknown Position")

            '''
                info_cn
            '''
            info_cn = info["info"]["cn"]
            # print(info_cn)
            # academic_cn
            if info_cn != []:
                if info_cn["academic"]:
                    academic_cn = info_cn["academic"].replace("\n", "")
                    # print(academic)
                    data.append(academic_cn)
                else:
                    data.append("Unknown CN Academic")
                # education_cn
                if info_cn["education"]:
                    education_cn = info_cn["education"].replace("\n", "")
                    data.append(education_cn)
                else:
                    data.append("Unknow CN Education")
            else:
                data.append("Unknow CN Academic")
                data.append("Unknow CN Education")
                
            '''
                info_en
            '''
            info_en = info["info"]["en"]
            if info_en != []:
                # academic_en
                if info_en["academic"]:
                    academic_en = info_en["academic"].replace("\n", "")
                    # print(academic)
                    data.append(academic_en)
                else:
                    data.append("Unknown EN Academic")
                # education_en
                if info_en["education"]:
                    education_en = info_en["education"].replace("\n", "")
                    data.append(education_en)
                else:
                    data.append("Unknow EN Education")
                
            else:
                data.append("Unknow EN Academic")
                data.append("Unknow EN Education")
                
            '''
                teacher_title
            '''
            teacher_title = info["teacher_title"]
            # title_cn
            if teacher_title["title_cn"]:
                title_cn = teacher_title["title_cn"]
                data.append(title_cn)
            else:
                data.append("Unknown Teacher Title")
            
            # title_en
            if teacher_title["title_en"]:
                title_en = teacher_title["title_en"]
                data.append(title_en)
            else:
                data.append("Unkonwn Teacher Title")

            # print(data)
            datalist.append(data)
        print("Crawler{} Done!!".format(i))
        
    # print(datalist)
    return datalist


def tdata_anaysis(datalist):
    # print(datalist)
    for data in datalist:
        if len(data) != 11:
            print(data)
            print(len(data))
        

if __name__ == "__main__":
    datalist = teacher_data()
    tdata_anaysis(datalist)